import Vue from 'vue'
import App from './App.vue'
import router from '@/router'
import store from '@/store'


import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
//element 默认配置
Vue.use(ElementUI, {
    size: 'small'
});


//主css
import '@/assets/css/index.scss';

//svg文件夹
import '@/assets/icons'
//引入阿里巴巴矢量图
import '@/assets/Alibaba-Icon/iconfont.css'

//注册全局组件
import '@/assets/utils/signinComponents';


//监听 sessionStorage
Vue.prototype.resetSetItem = function (key, newVal) {
    if (key === 'tabsViewArray') {
        // 创建一个StorageEvent事件
        let newStorageEvent = document.createEvent('StorageEvent');
        const storage = {
            setItem: function (k, val) {
                sessionStorage.setItem(k, val);
                // 初始化创建的事件
                newStorageEvent.initStorageEvent('setItem', false, false, k, null, val, null, null);
                // 派发对象
                window.dispatchEvent(newStorageEvent)
            }
        }
        return storage.setItem(key, newVal);
    }
}

//加载路由守卫
import '@/assets/utils/routerGuard'

//公用类
import Utils from "@/assets/utils/utils";
Vue.prototype.Utils = Utils;

//代码生成组件公用方法
import HandleUtils from "@/assets/utils/handleUtils";
Vue.prototype.HandleUtils = HandleUtils;

//阻止多次弹窗
import {message} from '@/assets/js/resetMessage';

//api挂载全局，统一调用
import allApi from "@/api/index";

allApi.keys().map(item => {
    Object.keys(allApi(item)).forEach(key => {
        Vue.prototype["$" + key] = allApi(item)[key];
    })
})

//阻止多次弹窗 调用
Vue.prototype.$message = message;

//阻止显示生产模式的消息
Vue.config.productionTip = false

//清除缓存
const VUE_APP_VERSION = require('../package.json').version
const vers = window.localStorage.getItem("appVersion");
if(VUE_APP_VERSION != vers){
    localStorage.clear()
    window.localStorage.setItem("appVersion", VUE_APP_VERSION);
    location.reload()
}

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')
